package com.hd.tiyu.yuejian.Activity;


import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;


import com.hd.tiyu.yuejian.Adapter.GuanZhuAdapter;
import com.hd.tiyu.yuejian.JavaBean.GuanZhu;
import com.hd.tiyu.yuejian.Model.UserModel;
import com.hd.tiyu.yuejian.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class GuanZhuActivity extends AppCompatActivity {
    private ImageView back;
    RecyclerView recyclerView;
    private String User_Id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.guan_zhu);
        User_Id=getIntent().getStringExtra("User_Id");
        initViews();
        //initData();
        initEvens();
        initData1();
    }

    private void initData1() {
        UserModel usermodel=new UserModel();
        Call<List<GuanZhu>> call=usermodel.getGuanZhu(User_Id);
        call.enqueue(new Callback<List<GuanZhu>>() {
            @Override
            public void onResponse(Call<List<GuanZhu>> call, Response<List<GuanZhu>> response) {
                List<GuanZhu> data=response.body();
                recyclerView.setAdapter(new GuanZhuAdapter(GuanZhuActivity.this,data));

            }

            @Override
            public void onFailure(Call<List<GuanZhu>> call, Throwable t) {
                Toast.makeText(GuanZhuActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

//    private void initData() {
//        UserModel model=new UserModel();
//        Call<List<GuanZhu>> call=model.getGuanZhu(User_Id);
//        call.enqueue(new Callback<List<GuanZhu>>() {
//            @Override
//            public void onResponse(Call<List<GuanZhu>> call, Response<List<GuanZhu>> response) {
//                List<GuanZhu> data=response.body();
//            }
//
//            @Override
//            public void onFailure(Call<List<GuanZhu>> call, Throwable t) {
//
//            }
//        });
//    }

    private void initViews() {
        back=(ImageView)findViewById(R.id.img_guanzhu_back);
        recyclerView=(RecyclerView) findViewById(R.id.guanzhulist);
        recyclerView.setLayoutManager(new LinearLayoutManager(GuanZhuActivity.this));

    }



    private void initEvens() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }


}
